<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>信息编辑</title>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/infobase.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/formvalid.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../ked/js/themes/default/default.css" />
        <link rel="stylesheet" href="../../ked/js/plugins/code/prettify.css" />
        <script charset="utf-8" src="../../ked/js/kindeditor-min.js"></script>
        <script charset="utf-8" src="../../ked/js/zh_CN.js"></script>
        <script charset="utf-8" src="../../ked/js/plugins/code/prettify.js"></script>
        <script type="text/javascript" src="http://cdn.uuola.cn/js/iColorPicker.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #panel{width:950px;}
            #panel table{width:940px;}
            span.s1{color:#B1B1B1;}
            #submitBtn{width:150px;height:35px;}
        </style>
    </head>
    <body>

        <div id="panel">
            <form id="InfoFrm" name="InfoFrm">
                <input type="hidden" value="" name="infoid" id="infoid" />
                <table>
                    <tr>
                        <th colspan="3">编辑信息</th>
                    </tr>
                    <tr>
                        <td class="r">所属板块：</td>
                        <td><span id="channeltype"></span></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td width="180" height="27" class="r">信息标题：</td>
                        <td width="49%">
                            <input name="title" type="text" id="title" tabindex="1" size="50" maxlength="60" valid="required" errmsg="信息标题不能为空!" />* 
                        </td>
                        <td width="34%"><div id="err_title"><span class="s1">信息标题.60个字符内.勿使用特殊字符.</span></div></td>
                    </tr>
                    <tr>
                        <td class="r">副标题：</td>
                        <td>
                            <input name="subtitle" type="text" id="subtitle"  tabindex="2" size="50"  maxlength="60" />
                            <span class="s1"> </span></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">摘要/概要：</td>
                        <td><label for="summary"></label>
                            <textarea name="summary" id="summary" cols="55" rows="4" tabindex="3" valid="limit" min="0" max="200" errmsg="摘要导读字数范围在200字内!"></textarea></td>
                        <td width="34%"><div id="err_summary"><span class="s1">摘要字数控制在200字内.</span></div></td>
                    </tr>
                    <tr>
                        <td class="r">来源/出处：</td>
                        <td><label for="origin"></label>
                            <input name="origin" type="text" id="origin" tabindex="4" size="50" maxlength="200"></td>
                        <td>&nbsp;<span class="s1">格式如：来源名|网址，或者只写来源名</span></td>
                    </tr>
                    <tr>
                        <td class="r">作者/发布者：</td>
                        <td><input name="author" type="text" id="author" tabindex="7" maxlength="30"></td>
                        <td>&nbsp;<span class="s1">管理员账号名</span></td>
                    </tr>
                    <tr>
                        <td class="r">信息类型：</td>
                        <td><script>out_infotype();</script></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">信息主图：</td>
                        <td><label for="pic"></label>
                            <input name="pic" type="text" id="pic" size="50">
                            <input type="button" name="uploadBtn" id="uploadBtn" value="上传图片" tabindex="5" onclick="TxBox.upload('pic', '-ms-ss-', '');">
                        </td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">跳转地址：</td>
                        <td><label for="gotourl"></label>
                            <input name="gotourl" type="text" id="gotourl" size="50" maxlength="500">
                        </td>
                        <td>&nbsp;<span class="s1">跳转地址以http://开头</span></td>
                    </tr>
                    <tr>
                        <td class="r">视频地址：</td>
                        <td><label for="vodurl"></label>
                            <input name="vodurl" type="text" id="vodurl" size="50" maxlength="100">
                        </td>
                        <td>&nbsp;<span class="s1">地址支持flv,mp4格式,以http://开头</span></td>
                    </tr>
                    <tr>
                        <td height="38"  class="r">信息标签：</td>
                        <td><div id="tagSelect"></div>
                            <input id="tagids" name="tagids" value="" type="hidden" />
                        </td>
                        <td>&nbsp;<input type="button" value="重新载入" onclick="reLoadTags();"/></td>
                    </tr>
                    <tr>
                        <td class="r">信息内容：</td>
                        <td>&nbsp;</td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r" colspan="3">
                            <textarea name="content" id="content" cols="150" rows="20"></textarea></td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td><input type="hidden" name="channeltype" id="channeltype" value="" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">&nbsp;</td>
                        <td class="c"><input name="submitBtn" type="button" class="button medium orange" id="submitBtn" tabindex="7" value="保存信息" onClick="Info.submit();" /></td>
                        <td>&nbsp;</td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                        <td class="c"></td>
                        <td>&nbsp;</td>
                    </tr>
                </table>
            </form>
        </div>



        <script type="text/javascript">
            var infoid = ut.get('infoid');
            var frm = ut.e('InfoFrm');
            var g_cid = 0;
            initValid(frm);
            
            function initFormData(){
                if(va.isnull(infoid)){
                    ut.m('信息ID参数错误');
                    return;
                }
                var p={'infoid':infoid,'t':ut.r()};
                $.get('../app/infobase/query_infobase_edit.shtm',$.param(p),function(x){
                    if(typeof x == 'string'){
                        ut.m('初始化表单错误.'+x);
                        return;
                    }
                    g_cid = x.cid;
                    $('#infoid').val(infoid);
                    $('#channeltype').text(getChannelType(x.channeltype));
                    $('#title').val(x.title);
                    $('#subtitle').val(x.subtitle);
                    $('#summary').val(x.summary);
                    $('#origin').val(x.origin);
                    $('#author').val(x.author);
                    $('#infotype').val(x.infotype);
                    $('#pic').val(x.pic);
                    $('#gotourl').val(x.gotourl);
                    $('#vodurl').val(x.vodurl);
                    contentEditor.html(x.content);
                    loadTags(x.cid);
                });
            };
            
            // 初始化编辑器
            var contentEditor ; 
            KindEditor.ready(function(K) {
                contentEditor = K.create('#content', {
                    uploadJson : KindUpload.UploadUrl,
                    fileManagerJson : KindUpload.fileMgrUrl,
                    allowFileManager : true,
                    afterCreate : function() {
                        var self = this;
                        self.sync();
                    }
                });
                prettyPrint();
                initFormData();
            });
            
            var Info ={
                submit:function(){
                    contentEditor.sync();
                    setTagids();
                    if(validator(frm)){
                        $.post('../app/infobase/update.shtm',ut.getFormData('#InfoFrm'),function(x){
                            if($.trim(x)=='ok'){
                                ut.m('更新成功!');
                                win.close();
                            }else{
                                ut.m('更新失败. '+x);
                            }   
                        });
                    }
                }
            };     


            function loadTags(cid){
                if(va.isnull(cid)){
                    return;
                }
                var t = '<label><input name="tagid" id="tagid@tagid" type="checkbox" value="@tagid"/>@tagname</label>';
                var p={
                    'cid':cid,
                    'pubstate':1,
                    't':ut.r()
                };
                var s =[];
                var jqTagSelect = $('#tagSelect');
                jqTagSelect.html('正在读取标签信息...');
                $.get('../app/tags/query_list.shtm',$.param(p),function(x){
                    if(x.length>0){
                        for(var k in x){
                            s.push(t.replace(/@tagid/g,x[k].tagid).replace(/@tagname/,x[k].tagname)); 
                        }
                        jqTagSelect.html(s.join(''));
                        loadInfotags();
                    }else{
                        jqTagSelect.html('没有标签可供选择'); 
                    }
                });
            };
            
            function loadInfotags(){
                $.get('../app/infotags/query_list.shtm','infoid='+infoid,function(x){
                    if(x.length>0){
                        for(var k in x){
                            ut.e('tagid' + x[k].tagid).checked = 'checked';
                        }
                    }
                });
            };
            
            function reLoadTags(){
                loadTags(g_cid);
            };
            
            function setTagids(){
                var tagids = ut.getselv('tagid');
                if(!va.isnull(tagids)){
                    $('#tagids').val(tagids);
                }
            };
            
        </script>
    </body>
</html>